        @extends('backend.layouts.default')

        @section('title')添加权限@endsection

        @section('brief')您可以在此页面添加权限信息@endsection

        @section('content')
            @include('backend.commons.sidebar')
            <!-- BEGIN CONTENT -->
            <div class="page-content-wrapper">
                <!-- BEGIN CONTENT BODY -->
                <div class="page-content">
                     <!-- BEGIN PAGE HEADER-->
                    @include('backend.commons.title')
                    <div class="page-bar">
                        <ul class="page-breadcrumb">
                            <li>
                                <i class="icon-home"></i>
                                <a href="{{ url('/admin/dashboard') }}">管理首页</a>
                                <i class="fa fa-angle-right"></i>
                            </li>
                            <li>
                                <a href="{{ url('/admin/permissions') }}">权限管理</a>
                                <i class="fa fa-angle-right"></i>
                            </li>
                            <li>
                                <span>@yield('title')</span>
                            </li>
                        </ul>
                    </div>
                    <!-- END PAGE HEADER-->
                    
                    <!-- BEGIN ADD -->
                    <div class="portlet light ">
                        <div class="portlet-body form">
                            <!-- BEGIN FORM-->
                            <form  id="createPermission" class="form-horizontal">
                                <div class="form-body">
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="required" aria-required="true"> * </span>名称</label>
                                        <div class="col-md-2">
                                            <input type="text" name="name" class="form-control" placeholder="权限代号(英文)">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="required" aria-required="true"> * </span>别名</label>
                                        <div class="col-md-2">
                                            <input type="text" name="display_name" class="form-control" placeholder="显示名称(中文)">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="required" aria-required="true"> * </span>权限组</label>
                                        <div class="col-md-2">
                                            <select name="permissionGroupId" class="form-control input-sm select2">
                                                <option value=""></option>
                                                @foreach($permissionGroups as $permissonGroup)
                                                <option value="{{ $permissonGroup->id }}">{{ $permissonGroup->display_name }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group last">
                                        <label class="col-md-3 control-label">描述</label>
                                        <div class="col-md-4">
                                            <textarea name="description" class="form-control" rows="3" placeholder="权限描述"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-actions">
                                    <div class="row">
                                        <div class="col-md-offset-3 col-md-4">
                                            <a href="javascript:;" id="create" class="btn green">保存</a>
                                            <a href="javascript:;" id="createAndContinue" class="btn green">保存并继续添加</a>
                                            <a href="{{ url('/admin/permissions') }}" type="button" class="btn default">返回列表</a>
                                        </div>
                                    </div>
                                </div>
                            </form>
                            <!-- END FORM-->
                        </div>
                    </div>
                    <!-- END EDD -->
                </div>
                <!-- END CONTENT BODY -->

                @push('styles')
                <link href="{{ config('app.static_url') }}assets/global/plugins/select2/css/select2.min.css" rel="stylesheet" type="text/css" />
                <link href="{{ config('app.static_url') }}assets/global/plugins/select2/css/select2-bootstrap.min.css" rel="stylesheet" type="text/css" />
                @endpush

                @push('scripts')
                <script src="{{ config('app.static_url') }}assets/global/plugins/select2/js/select2.full.min.js" type="text/javascript"></script>
                <script>

                    $(".select2").select2({placeholder:'请选择权限组',width: '100%'});

                    /********************
                    |
                    | 表单处理
                    |
                    \********************/
                    var doCreateFunc = function() {
                        var formDom = $('#createPermission');
                        var name = formDom.find('[name=name]').val();
                        var display_name = formDom.find('[name=display_name]').val();
                        var group_id = formDom.find('[name=permissionGroupId]').val();
                        var description = formDom.find('[name=description]').val();
                        var redirect = '{{ url('/admin/permissions') }}';

                        $.ajax({
                            url: '{{ url('/admin/permissions') }}',
                            type: 'post',
                            datatype: 'json',
                            formDom: formDom,
                            bindDom: $('#create'),
                            bindType: 'click',
                            bindFunc: doCreateFunc,
                            data: {
                                name: name, 
                                display_name: display_name,
                                group_id:group_id, 
                                description: description, 
                                redirect:redirect
                            }
                        });
                    };

                    var doCreateAndContinueFunc = function() {
                        var formDom = $('#createPermission');
                        var name = formDom.find('[name=name]').val();
                        var display_name = formDom.find('[name=display_name]').val();
                        var group_id = formDom.find('[name=permissionGroupId]').val();
                        var description = formDom.find('[name=description]').val();
                        var redirect = '{{ url('/admin/permissions/create') }}';

                        $.ajax({
                            url: '{{ url('/admin/permissions') }}',
                            type: 'post',
                            datatype: 'json',
                            formDom: formDom,
                            bindDom: $('#createAndContinue'),
                            bindType: 'click',
                            bindFunc: doCreateAndContinueFunc,
                            data: {
                                name: name, 
                                display_name: display_name,
                                group_id:group_id, 
                                description: description, 
                                redirect:redirect
                            }
                        });
                    };
                    $(function() {
                        $('#create').bind('click', doCreateFunc);
                        $('#createAndContinue').bind('click', doCreateAndContinueFunc);
                    });
                </script>
                @endpush
            </div>
        @endsection